<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/8/9
  Time: 0:48
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
    <title>修改电池信息页面</title>
</head>
<body>
<h1 align="center">修改电池信息页面</h1>
<form action="Update" method="post">
    <table align="center" border="2px">
        <c:forEach var="p" items="${sessionScope.p}">
            <tr>
                <td>车辆类型:</td>
                <td style="display: none"><input type="text"  name="id" value="${p.id}"></td>
                <td><input type="text" id="carName" name="carName" value="${p.carname}"></td>
            </tr>
        <tr>
            <td>所属城市:</td>
            <td><input type="text" id="cityName" name="cityName" value="${p.cityname}"></td>
        </tr>
        <tr>
            <td>使用单位:</td>
            <td><input type="text" id="userName" name="userName" value="${p.username}"></td>
        </tr>
        <tr>
            <td>压差报警值:</td>
            <td><input type="text" id="pressureValue" name="pressureValue" value="${p.pressurevalue}">
            </td>
        </tr>
        <tr>
            <td>报警时间:</td>
            <td><input type="text" id="time" name="time" value="${p.time}"></td>
        </tr>
        <tr>
            <td>操作:</td>
            <td><input type="submit" onclick="Update()" value="修改" name="update"></td>
        </tr>
        </c:forEach>
    </table>
</form>
</body>
<script>
    var a = true;
    $("form").submit(function () {
        return a;
    })
    function Update() {
        var tiem = $("#time").val().trim();
        var pattern = /^[0-9]{4}-[0-1]?[0-9]{1}-[0-3]?[0-9]{1}$/;
        if ($("#carName").val().trim() == "" || $("#cityName").val().trim() == "" || $("#userName").val().trim() == "" ||
            $("#pressureValue").val().trim() == "" || $("#time").val().trim() == "") {
            alert("请填写完整的信息")
            a = false;
        } else if (isNaN($("#pressureValue").val().trim())) {
            alert("压差报警值必须是数值类型")
            a = false;
        } else if (!(pattern.test(tiem))) {
            alert("时间格式不合法，正确格式是yyyy-MM-dd")
            a = false;
        }
    }
</script>
</html>
